
var dNow = new Date();
var vDay;
function CalendarClick(yearD)
{
	vDay = yearD;
	obCal.OpenCalWindow(dNow);
}

function CallBackSetDate(ADate){

	if(( ADate  == null ) ||( typeof(ADate)  == "undefined" ))
	{
		return ;
	}
	var temp = "";
	temp +=  ADate.getFullYear();
	var vMonth = "" + (ADate.getMonth() + 1);
	var vDate = "" + (ADate.getDate());
	if(vMonth.length <2){
		vMonth = '0' + vMonth;
	}
	if(vDate.length <2){
		vDate = '0' + vDate;
	}
	//document.forms[0][vDay].value = temp + "-" + vMonth + "-" + vDate;
    vDay.value = temp + "-" + vMonth + "-" + vDate;
}

function GetYear( AiMonth, AiDate )
{

	if( AiMonth < parseInt( dNow.getMonth() ) +1 )
	{
		return parseInt( dNow.getFullYear() ) +1;
	}
	if(( AiMonth < parseInt( dNow.getMonth() ) +1  ) && (  AiDate < parseInt( dNow.getDate()  )  ))
	{
		return parseInt( dNow.getFullYear() ) +1;
	}
	else
		return parseInt( dNow.getFullYear() );
}

function AddDate( AiMonth, AiDate, AiAddDate )
{
	var dDate = new Date(GetYear( AiMonth, AiDate ),  parseInt( AiMonth )-1, AiDate );
	dDate.setDate( AiDate + AiAddDate );
	dateRet = dDate;
	return dDate;
}


var obCal;
obCal = new Cal(this);

function Cal( AWhnd ){

	this.mstrBrowser = window.navigator.appName;

	this.hwnd = null;
	this.ParentWHnd = AWhnd;
	this.mdDate = null;
	this.OpenCalWindow = OpenCalWindow;
	this.CloseCallBack = CloseCallBack;
	this.CloseCalWindow = CloseCalWindow;

}

function CloseCallBack(ADate){
	this.mdDate = ADate;
	this.ParentWHnd.CallBackSetDate(this.mdDate);
	if(this.mstrBrowser != "Microsoft Internet Explorer")
	{
		this.CloseCalWindow();
	}
}

function CloseCalWindow(){
	if(this.hwnd == null )
	{
		return;
	}
	if(this.hwnd.closed == false )
	{
		this.hwnd.close();
	}
}

function OpenCalWindow(ADate)
{
	var iLeft;
	var iTop;
	var iWidth;
	var iHeight;
	var strParam;

	this.mdDate = ADate;
	if(this.mstrBrowser == "Microsoft Internet Explorer")
	{
		this.mdDate = window.showModalDialog("../../resource/calendar/dcCalendar.htm", ADate ,"dialogWidth:210px; dialogHeight:240px; center:yes; status:no; resizable:no; help:no" );
		this.CloseCallBack(this.mdDate);
	}
}



